<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="../js/vue.js"></script>
	</head>
	<body>
		<div id="root">
			<h2>人员信息</h2>
			<input type="text" placeholder="请输入名称" v-model="keyword"/>
			<ul>
				<!-- <li v-for="p in persons" :key="p.id"> -->
				<li v-for="(p,index) of filterPersons" :key="index">
					{{p.name}}-{{p.age}}
				</li>
			</ul>
		</div>
	</body>
	<script>
		// #region
		new Vue({
			el:'#root',
			data(){
				return {
					persons:[
						{id:'001',name:'张三',age:12},
						{id:'002',name:'李四',age:13},
						{id:'003',name:'王五',age:14}
					],
					keyword:'',
					// filterPersons:[]
				}
			},
			// watch:{
			// 	keyword:{
			// 		immediate:true,
			// 		handler(val){
			// 			this.filterPersons = this.persons.filter((p) => {
			// 				return p.name.includes(val)
			// 			})
			// 		}
			// 	}
			// }
			computed:{
				filterPersons(){
					return this.filterPersons = this.persons.filter((p) => {
									return p.name.includes(this.keyword)
								})
				}
			}
		})
		//#endregion
	</script>
</html>